# -*- encoding : utf-8 -*-
#---------------------------------------
# Tu
#---------------------------------------
class Admin::FacultyController < ApplicationController
  # specific layout
  layout 'admin/application'
  
  def index
    @faculties = Faculty.paginate(:page => params[:page], :per_page => 10)
  end

  # add new faculty
  def new
    @faculty = Faculty.new
  end
  def create
    @faculty = Faculty.new(params[:faculty])
    if @faculty.save
      flash[:notice] = "Create successfully"
      redirect_to :controller => "admin/faculty", :action => "view", :id => @faculty.id
    else
      flash[:notice] = "There are some errors"
      render "new"
    end
    
  end
  
  # edit faculty
  def edit
    @faculty = Faculty.find(params[:id])
  end
  def update
    @faculty = Faculty.find(params[:id])
    if @faculty.update_attributes(params[:faculty])
      redirect_to :controller => "admin/faculty", :action => "view", :id => @faculty.id
    else
      render "edit"
    end
  end
  
  # view the faculty info
  def view
    @faculty = Faculty.find(params[:id])
  end
  
  # delete the faculty
  def delete
    @faculty = Faculty.find(params[:id])
    @faculty.destroy
    
    redirect_to :controller => "admin/faculty", :action => "index"
  end
end








